package com.lac.component.rabbitmq.dead;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.time.LocalDateTime;

/**
 * @author xiaokuixiao
 * date2025/6/27 14:48
 */
@Component
public class MessageConsumer {
    @RabbitListener(queues = DeadLetterConfig.DEAD_LETTER_QUEUE)
    public void handleDeadLetterMessage(Message message,Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
//        System.out.println("[" + LocalDateTime.now() + "] 收到延迟消息: " + new String(message.getBody()));
        // 处理延迟后的业务逻辑
        channel.basicAck(tag,true);
    }
    @RabbitListener(queues = DelayedConfig.DELAYED_QUEUE_NAME)
    public void receiveDelayedMessage(String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
//        System.out.println("[" + LocalDateTime.now() + "] : " + message);
        channel.basicAck(tag,true);
    }
}
